﻿/*
 * Created by SharpDevelop.
 * User: CrOnO
 * Date: 19/10/2011
 * Time: 10:00 p.m.
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using Business_Entity;
using System.Collections.Generic;

namespace DAOFactory
{
	/// <summary>
	/// Description of DAOAreaCargo.
	/// </summary>
	public class DAOAreaCargo
	{
		public DAOAreaCargo()
		{
		}
		
		public List<BEArea> completarArea()
		{
			try
			{
				//ConnectionManager.closeConnection();
				SqlCommand cmd = new SqlCommand("RRHH_OBTENER_AREA_L", ConnectionManager.getConnection());
				cmd.CommandType = CommandType.StoredProcedure;
					
				SqlDataReader amd = cmd.ExecuteReader();
				List<BEArea> lista = new List<BEArea>();
				
				if (amd.HasRows) 
				{
					while(amd.Read())
					{
						BEArea area = new BEArea();
									
						try
						{
							area.IdArea = int.Parse(amd[0].ToString());
							area.Descripcion = amd[1].ToString();
							lista.Add(area);
						}
						catch
						{
//							System.Windows.Forms.MessageBox.Show("Error al obtener Area","Error");
							amd.Close();
							return null;
						}
					}
					amd.Close();
					return lista;
				}
				else
				{
					amd.Close();
					return null;
				}
			}
			catch
			{
				return null;
			}
		}
		
		public List<BECargo> completarCargo(String area)
		{
			try
			{
				//ConnectionManager.closeConnection();
				SqlCommand cmd = new SqlCommand("RRHH_OBTENER_CARGO_L", ConnectionManager.getConnection());
				cmd.CommandType = CommandType.StoredProcedure;
				
				cmd.Parameters.Add("@AREA", SqlDbType.VarChar, 50);
				cmd.Parameters["@AREA"].Value = area;
				
				SqlDataReader amd = cmd.ExecuteReader();
				List<BECargo> lista = new List<BECargo>();
				
				if (amd.HasRows) 
				{
					while(amd.Read())
					{
						BECargo cargo = new BECargo();
						try
						{
							cargo.IdCargo=int.Parse(amd[1].ToString());
							cargo.IdArea=int.Parse(amd[0].ToString());
							cargo.Descripcion=amd[2].ToString();
							lista.Add(cargo);
						}
						catch
						{
//							System.Windows.Forms.MessageBox.Show("Error al obtener Cargo","Error");
							amd.Close();
							return null;
						}
					}
					amd.Close();
					return lista;
					//ConnectionManager.closeConnection();				
				}
				else
				{
					amd.Close();
					//ConnectionManager.closeConnection();
					return null;
				}	
			}
			catch
			{
				return null;
			}
		}
	}
}
